/* Base styles with mobile-first approach */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    overflow: hidden;
}

/* Responsive container - adapts to iframe vs full browser */
.app-container {
    display: flex;
    width: 100%;
    height: 450px; /* Default iframe height */
    position: relative;
}

/* Full browser detection */
@media (min-height: 500px) {
    .app-container {
        height: 90vh;
    }
}

/* Tooltip for header information - saves vertical space */
.tooltip {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    opacity: 0;
    pointer-events: none;
    z-index: 1000;
    transition: opacity 0.3s ease;
    text-align: center;
    max-width: 300px;
}

.app-container:hover .tooltip {
    opacity: 1;
}

/* Left sidebar with draggable items */
.sidebar {
    width: 220px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-right: 2px solid rgba(255, 255, 255, 0.3);
    overflow-y: auto;
    padding: 10px;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
}

.category-section {
    margin-bottom: 15px;
}

.category-title {
    font-size: 14px;
    font-weight: bold;
    margin-bottom: 8px;
    padding: 6px 8px;
    border-radius: 4px;
    text-align: center;
}

/* Color coding for categories - Singapore curriculum aligned */
.category-title.characters, .draggable-item.characters, .concept-item.characters {
    background: #3498db;
    color: white;
}

.category-title.themes, .draggable-item.themes, .concept-item.themes {
    background: #2ecc71;
    color: white;
}

.category-title.events, .draggable-item.events, .concept-item.events {
    background: #f1c40f;
    color: #2c3e50;
}

.category-title.devices, .draggable-item.devices, .concept-item.devices {
    background: #9b59b6;
    color: white;
}

/* Draggable items with touch-friendly sizing */
.draggable-item {
    padding: 8px 10px;
    margin: 4px 0;
    border-radius: 6px;
    cursor: grab;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.2s ease;
    user-select: none;
    min-height: 36px; /* Touch-friendly minimum */
    display: flex;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.draggable-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.draggable-item:active {
    cursor: grabbing;
    transform: scale(0.95);
}

/* Main concept map area - Updated to accommodate fixed reflection panel */
.concept-map {
    flex: 1;
    position: relative;
    /* Adjusted to account for fixed reflection panel width */
    margin-right: 300px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(5px);
    overflow: hidden;
}

.map-instructions {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: rgba(0, 0, 0, 0.6);
    font-size: 14px;
    pointer-events: none;
}

.map-instructions p {
    margin: 5px 0;
}

/* Concept items in the map */
.concept-item {
    position: absolute;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: move;
    font-size: 12px;
    font-weight: 500;
    min-width: 80px;
    text-align: center;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
    z-index: 10;
    border: 2px solid transparent;
}

.concept-item:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
}

.concept-item.selected {
    border-color: #ff6b6b;
    box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.3);
}

/* Connection lines */
.connection-line {
    position: absolute;
    height: 2px;
    background: #ff6b6b;
    transform-origin: left center;
    z-index: 5;
    pointer-events: none;
}

.connection-label {
    position: absolute;
    background: rgba(255, 107, 107, 0.9);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 500;
    z-index: 6;
    pointer-events: none;
    white-space: nowrap;
}

/* Modal for creating connections */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.modal-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    min-width: 300px;
    max-width: 90%;
}

.modal-content h3 {
    margin-bottom: 15px;
    color: #2c3e50;
}

.modal-content select,
.modal-content input {
    width: 100%;
    padding: 10px;
    margin: 8px 0;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
}

.modal-buttons {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

.modal-buttons button {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 6px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

#createConnection {
    background: #2ecc71;
    color: white;
}

#createConnection:hover {
    background: #27ae60;
}

#cancelConnection {
    background: #95a5a6;
    color: white;
}

#cancelConnection:hover {
    background: #7f8c8d;
}

/* Fixed reflection panel on the right - Updated to be always visible */
.reflection-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 300px;
    height: 100%;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 20px;
    box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
    z-index: 500;
    overflow-y: auto;
    /* Always visible - removed transition and positioning logic */
}

.reflection-panel h3 {
    color: #2c3e50;
    margin-bottom: 15px;
}

.reflection-panel p {
    color: #2c3e50;
    margin-bottom: 15px;
    font-size: 14px;
    line-height: 1.4;
}

.reflection-panel textarea {
    width: 100%;
    height: 200px;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    resize: vertical;
    font-family: inherit;
    margin-bottom: 15px;
}

.reflection-panel button {
    width: 100%;
    padding: 12px;
    background: #3498db;
    color: white;
    border: none;
    border-radius: 6px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease;
}

.reflection-panel button:hover {
    background: #2980b9;
}

/* Control buttons - Updated positioning to account for fixed reflection panel */
.controls {
    position: absolute;
    bottom: 15px;
    right: 320px; /* Moved left to avoid overlap with reflection panel */
    display: flex;
    gap: 8px;
    z-index: 100;
}

.controls button {
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.controls button:hover {
    background: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

/* Mobile responsiveness - Updated for fixed reflection panel */
@media (max-width: 768px) {
    .concept-map {
        margin-right: 0; /* Remove margin on mobile */
    }
    
    .reflection-panel {
        width: 100%;
        height: 40%;
        top: 60%;
        right: 0;
    }
    
    .sidebar {
        width: 180px;
    }
    
    .draggable-item {
        font-size: 11px;
        padding: 6px 8px;
    }
    
    .concept-item {
        font-size: 11px;
        padding: 6px 10px;
        min-width: 70px;
    }
    
    .controls {
        bottom: 10px;
        right: 10px;
    }
    
    .controls button {
        padding: 6px 10px;
        font-size: 11px;
    }
}

/* Drag and drop visual feedback */
.concept-map.drag-over {
    background: rgba(255, 255, 255, 0.95);
}

.draggable-item.dragging {
    opacity: 0.5;
    transform: rotate(5deg);
}

/* Loading and success states */
.success-message {
    position: fixed;
    top: 20px;
    right: 320px; /* Adjusted to not overlap with reflection panel */
    background: #2ecc71;
    color: white;
    padding: 10px 15px;
    border-radius: 6px;
    font-size: 14px;
    z-index: 1001;
    opacity: 0;
    transform: translateX(100%);
    transition: all 0.3s ease;
}

.success-message.show {
    opacity: 1;
    transform: translateX(0);
}